%::PROVIDES=(
	name	=> ["PNODE","DEPENDS_ON","AUTOSTARTLIST"],
	desc	=> ["Get application preferred node","Get application dependencies",
			"Get list of auto-start applications"],
	type	=> "request",
	code	=> \&::do_handle_pnode
);

#########################################################################
# Here we handle the "PNODE APP=fred" - where we returned the		#
# node the specified application prefers to be used on.			#
# Also called for the "DEPENDS_ON APP=fred" request - which returns	#
# a list of other packages that should be running before this		#
# package is started.							#
# Also called for AUTOSTARTLIST - to return a list of registered	#
# applications that are configured to want automatic starting.		#
#########################################################################

sub ::do_handle_pnode {
my $args=shift;
my $cmdname=$args->{"_CMDNAME"};
my ($nutil,$node,$rc,$estr);

	if($cmdname eq "AUTOSTARTLIST") {
		my ($capp,$xx,@c);
		@c=();
		foreach $capp (keys(%{$appmap})) {
			if(exists($appmap->{$capp}->{XMLINFO}->{global}->{autostart})) {
				$xx=lc($appmap->{$capp}->{XMLINFO}->{global}->{autostart});
				if(is_true($xx)) {
					push @c,$capp;
				}
			}
		}
		return "OK ".join(",",@c);

	}
	if(!exists($args->{APP})) {
		logwarn("$cmdname request missing APP argument");
		return "MISSING_ARG";
	}

	$nutil=new nodeutils($appmap);
	if(!defined($nutil)) {
		logwarn("Unable to create nutil object for PNODE or DEPENDS_ON request.");
		return "INTERNAL_ERROR";
	}

	#################################################################
	# Ok, we get details to return...				#
	#################################################################

	if($cmdname eq "PNODE") {
		($node,$rc,$estr)=$nutil->choose_node(APP => $args->{APP});

		if(!defined($node)) {
			return "ERROR $rc $estr";
		}
		return "OK $node";
	}

	if($cmdname eq "DEPENDS_ON") {
		my @clist=($nutil->getdependents($args->{APP}));
		@clist=() if !defined($clist[0]);
		return "OK ".join(",",@clist);
	}
	return "ERROR UNKNOWN_CMD";
}

1;

